<?php
require_once 'class/DataIn/AbstractDataIN.php';
require_once 'class/DataIn/AbstractDataIN.php';
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Time
 *
 * @author mateusz.ledzewicz
 */
class Average extends AbstractDataIN{
    
    public static $shortAVG = 5;
    public static $longAVG  = 30;
    protected $dataArray;
    
    public function __construct($isin, $date, $type, $numberOfData) {
        parent::__construct($isin, $date, $type, $numberOfData+self::$longAVG);
    }


    protected function prepareData() {
      
        $data = $this->getPreparedData();
       
        $count = count($data);
        $this->dataArray = array_values($data);
        foreach($this->dataArray as $key => $line){
            if($key+self::$longAVG>=$count)
                break;
            $this->data[] = array($this->avg($key, self::$shortAVG), $this->avg($key, self::$longAVG) );  
        }
      
    }
    
    protected function avg($start, $numberOfElements)
    {
        
        array_splice($this->dataArray, 0, $start);
        array_splice($this->dataArray, $numberOfElements);
        $sum = 0;
        foreach($this->dataArray as $line){
            $sum += $this->getValue($line);
        }
        return $sum/$numberOfElements;
        
        
        
    }
}

?>
